﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;


namespace BloomsburyBanHang
{
    public partial class Admin_ThanhToan : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txt_MaGui.Text = "6370264803241935";
            txt_MaNhan.Text = "340204808157595";
            try
            {
                string username = Session["username"].ToString();
                string pass = Session["pass"].ToString();
            }
            catch (Exception ex)
            {
                 this.Label1.Text = "Chua dang nhap vao nha mo gioi!!";
            }
        }

        protected void Btn_ThanhToan_Click(object sender, EventArgs e)
        {
            string maGui = txt_MaGui.Text;
            string maNhan = txt_MaNhan.Text;
            try
            {
                string username = Session["username"].ToString();               
                string pass = Session["pass"].ToString();
                int soTien = Convert.ToInt32(txt_SoTien.Text);
                string sid = Session["SID"].ToString();
                string strNhaMoiGioi = Session["NhaMoGioi"] as string;
                NhaMoiGioiDTO temp = this.stringToNhaMoiGioi(strNhaMoiGioi);
                NHA_MO_GIOI mogioi = NhaMoiGioiDTO.DiverseConvert(temp);
                //int kq = (int)WebserviceInvoker.WSInvoker.CallWebService("http://www.nh0660.somee.com/", "Service1", "Tranfer", new object[] { sid, maGui, maNhan, soTien });
                //int kq = service.Tranfer(sid, maGui, maNhan, soTien);
                int kq = (int)WebserviceInvoker.WSInvoker.CallWebService(mogioi.URL, mogioi.TenService, mogioi.TenHamTranfer, new object[] { sid, maGui, maNhan, soTien });
                switch (kq)
                {
                    case -1: this.Label1.Text = " Chua dang nhap hoac qua thoi gian dang nhap"; break;
                    case -2: this.Label1.Text = " User khong co quyen goi webservice thanh toan cua mo gioi"; break;
                    case -3: this.Label1.Text = " Ma the thanh toan khong hop le"; break;
                    case -4: this.Label1.Text = " Ma the gui khong hop le"; break;
                    case -5: this.Label1.Text = " ma the nhan khong hop le"; break;
                    case -6: this.Label1.Text = " khong ho tro ngan hang ma Nha kinh doanh muon thanh toan"; break;
                    case -7: this.Label1.Text = " khong ho tro ngan hang ben gui"; break;
                    case -8: this.Label1.Text = " khong ho tro ngan hang ben nhan"; break;
                    case -9: this.Label1.Text = " lay phi chuyen that bai"; break;
                    case -10: this.Label1.Text = " Ngan hang ben gui chuyen khoan that bai"; break;
                    case -11: this.Label1.Text = " Ngan hang ben nhan chuyen khoan that bai"; break;
                    default: this.Label1.Text = "chuyen khoan thanh cong!!! so tien tra ve " + kq; break;
                }
            }
            catch (Exception ex)
            {
                this.Label1.Text = "Chua dang nhap vao nha mo gioi!!";
               // Response.Redirect("Admin_Login.aspx");
            }
           
            //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
            //equest.CookieContainer = new CookieContainer();
          //  Service1 service = new Service1();
            //service.CookieContainer = new CookieContainer();
            
            //string sid = (string)WebserviceInvoker.WSInvoker.CallWebService("http://www.nh0660.somee.com/", "Service1", "Login", new object[] { username, pass });
            //string sid = service.Login(username, pass);
          

        }

        private NhaMoiGioiDTO stringToNhaMoiGioi(string str)
        {
            NhaMoiGioiDTO rs = new NhaMoiGioiDTO();
            str = WSRequest.EditToBasicFormat(str);
            WSRequest.XMLToObject<NhaMoiGioiDTO>(ref rs, str);
            return rs;
        }
    }
}